package com.example.mall.web.controller;

import com.example.mall.domain.ProductReviews;
import com.example.mall.dto.ProductReviewsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.ProductReviewsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IProductReviewsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productReviews")
public class ProductReviewsController {

    @Autowired
    public IProductReviewsService productReviewsService;

    /**
     * 分页查询商品审核表信息
     * @param productReviewsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询商品审核表信息",notes = "分页查询商品审核表信息",httpMethod = "GET")
    public JSONResult queryPage(ProductReviewsQuery productReviewsQuery){
        PageDTO<ProductReviewsDto> productReviewsDtoPageDTO = productReviewsService.queryPage(productReviewsQuery);
        return JSONResult.success("查询成功",productReviewsDtoPageDTO);
    }

    /**
     * 根据id查询商品审核表信息
     * @param reviewId
     * @return
     */
    @GetMapping("query/{reviewId}")
    @ApiOperation(value = "根据id查询商品审核表信息",notes = "根据id查询商品审核表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("reviewId")Long reviewId){
        //1.根据id查询用户信息
        if (reviewId == null){
            throw new GlobalCustomerException(ErrorEnumCode.REVIEWID_NOT_ID);
        }
        ProductReviews productReviews = productReviewsService.getById(reviewId);
        return JSONResult.success("查询成功",productReviews);
    }

    /**
     * 根据id查询商品审核表信息
     * @param reviewId
     * @return
     */
    @GetMapping("queryProductReviewsById/{reviewId}")
    @ApiOperation(value = "根据id查询商品审核表信息",notes = "根据id查询商品审核表信息",httpMethod = "GET")
    public JSONResult queryProductReviewsById(@PathVariable("reviewId")Long reviewId){
        //1.根据id查询用户信息
        if (reviewId == null){
            throw new GlobalCustomerException(ErrorEnumCode.REVIEWID_NOT_ID);
        }
        ProductReviews productReviews = productReviewsService.queryProductReviewsById(reviewId);
        return JSONResult.success("查询成功",productReviews);
    }

    /**
     * 查询全部商品审核表信息
     * @param
     * @return
     */
    @GetMapping("queryProductReviewsList")
    @ApiOperation(value = "查询全部商品审核表信息",notes = "查询全部商品审核表信息",httpMethod = "GET")
    public JSONResult queryProductReviewsList(){
        List<ProductReviews> productReviews = productReviewsService.queryProductReviewsList();
        return JSONResult.success("查询成功",productReviews);
    }

    /**
     * 新增商品审核表
     * @param productReviewsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增商品审核表",notes = "新增商品审核表",httpMethod = "POST")
    public JSONResult insert(@RequestBody ProductReviewsDto productReviewsDto){
        productReviewsService.insert(productReviewsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改商品审核表信息
     * @param productReviewsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改商品审核表信息",notes = "修改商品审核表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody ProductReviewsDto productReviewsDto){
        productReviewsService.update(productReviewsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除商品审核表信息
     * @param reviewId
     * @return
     */
    @PostMapping("delete/{reviewId}")
    @ApiOperation(value = "删除商品审核表信息",notes = "删除商品审核表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("reviewId") Long reviewId) {
        productReviewsService.delete(reviewId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除商品审核表信息
     * @param reviewIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除商品审核表信息",notes = "批量删除商品审核表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> reviewIds) {
        productReviewsService.deleteBatch(reviewIds);
        return JSONResult.success("批量删除成功");
    }
}
